//
//  YWPageControl.m
//  YueshengToutiao
//
//  Created by yellow on 2021/4/2.
//  Copyright © 2021 YW. All rights reserved.
//

#import "YWPageControl.h"

#define dotW 8
#define magrin 4


@implementation YWPageControl

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    
    //计算圆点间距
    CGFloat marginX = dotW + magrin;
    
    //计算整个pageControll的宽度
    CGFloat newW = (self.subviews.count) * marginX - magrin;
    
    //设置新frame
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, newW, self.frame.size.height);
    
    //设置居中
    CGPoint center = self.center;
    center.x = self.superview.width/2;
    self.center = center;
    
    //遍历subview,设置圆点frame
    for (int i = 0; i < [self.subviews count]; i++) {
        UIImageView* dot = [self.subviews objectAtIndex:i];
        [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dot.height)];
//        if (i == self.currentPage) {
//            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dot.height)];
//        }else {
//            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dot.height)];
//        }
    }
}

@end
